import subprocess
import os

import condor_config as config
from condor_python_worker.condor import Condor
from condor_python_worker.toolkit import notify

from example_hello_world.impl import jobs, collect


if __name__ == '__main__':
    subprocess.call('mv %s src > /dev/null'%config.SRC_DIR, shell=True)
    subprocess.call('tar czvf src.tar.gz src > /dev/null', shell=True)
    subprocess.call('mv src %s> /dev/null'%config.SRC_DIR, shell=True)
    if os.path.exists(config.POOL_DIR):
        subprocess.call('rm -rf %s/*'%config.POOL_DIR, shell=True)

    msg = '\n'.join(jobs)

    condor = Condor(jobs, collect)
    condor.run()

    notify(msg)

    subprocess.call('condor_rm -all', shell=True)
